--lua script
--处理装备系统相关操作

--#include "data\functions\Equip\EquipStar.lua" once 				--装备强化（升星）
--#include "data\functions\Equip\EquipInject.lua" once 				--装备注灵
--#include "data\functions\Equip\EquipFurnace.lua" once 			--神炉装备
--#include "data\functions\Equip\EquipSynthesis.lua" once 			--道具合成
--#include "data\functions\Equip\EquipSynthesisEx.lua" once 		--道具合成(新)
--#include "data\functions\Equip\EquipRecover.lua" once 			--装备回收
--#include "data\functions\Equip\EquipSmith.lua" once 				--装备洗炼
--#include "data\functions\Equip\EquipGodCast.lua" once 			--神铸装备
--#include "data\functions\Equip\EquipEnchant.lua" once 			--装备附魔
--#include "data\functions\Equip\EquipExchange.lua" once 			--装备互换
--#include "data\functions\Equip\EquipSynthesisEEx.lua" once 		--全装备升阶

--[[
//装备操作
enum tagEquipOP
{
	gEquipNoOP				= 0,	//占位
	gEquipStar				= 1,	//装备升星强化
	gEquipRecoverStar		= 2,	//装备损失星级恢复
	gEquipTransferStar		= 3,	//装备强化转移
	gEquipInject			= 4,	//装备注灵
	gEquipInjectRecycle		= 5,	//装备回收注灵
	gEquipFurnaceActivate	= 6,	//神炉装备激活
	gEquipFurnaceUpgrade	= 7,	//神炉装备升级
	gEquipSynthesis			= 8,	//道具合成
	gEquipRecover			= 9,	//装备回收
	gEquipSmithFresh		= 10,	//装备属性洗练
	gEquipSmithTrans		= 11,	//装备洗练属性转移
	gEquipGodCastUpgrade	= 12,	//装备升阶
	gEquipEnchant			= 13,	//装备附魔
	gEquipTSArmyUpgrade		= 14,	//所有装备生阶
};
]]

EquipOpFuncList = {}


EventCallDispatcher.HandlerEquipOp = function (sysarg, args)
	if args[1] == nil then 
		return 
	end

	local func = EquipOpFuncList[args[1]]
	if func ~= nil then
		func(sysarg, args)
	end
end

--装备强化
EquipOpFuncList[gShowEquipData] = function(sysarg, args)
	local itemPtr 	= args[2]
	ShowEquipData(sysarg, itemPtr)
end

--装备强化
EquipOpFuncList[gEquipStar] = function(sysarg, args)
	local itemPtr 	= args[2]
	local flag 		= args[3]
	EquipStar(sysarg, itemPtr, flag)
end

--恢复损失星级
EquipOpFuncList[gEquipRecoverStar] = function(sysarg, args)
	local itemPtr 	= args[2]
	local flag 		= args[3]
	EquipRecoverStar( sysarg, itemPtr )
end

--装备强化转移
EquipOpFuncList[gEquipTransferStar] = function(sysarg, args)
	local srcEquipPtr 	= args[2]
	local desEquipPtr 	= args[3]
	EquipTransferStar( sysarg, srcEquipPtr, desEquipPtr )
end

--装备注灵
EquipOpFuncList[gEquipInject] = function(sysarg, args)
	local itemPtr 	= args[2]
	EquipInject(sysarg, itemPtr)
end

--装备注灵回收
EquipOpFuncList[gEquipInjectRecycle] = function(sysarg, args)
	local itemPtr 	= args[2]
	EquipInjectRecycle(sysarg, itemPtr)
end

--神炉装备激活
EquipOpFuncList[gEquipFurnaceActivate] = function(sysarg, args)
	local equipFurnaceIdx = args[2]
	EquipFurnaceActivate(sysarg, equipFurnaceIdx)
end

--神炉装备升级
EquipOpFuncList[gEquipFurnaceUpgrade] = function(sysarg, args)
	local equipFurnaceIdx = args[2]
	EquipFurnaceUpgrade(sysarg, equipFurnaceIdx)
end

--道具合成
EquipOpFuncList[gEquipSynthesis] = function(sysarg, args)
	--ItemSynthesis(sysarg, args)
	ItemSynthesisEx(sysarg, args)
end


--装备回收
EquipOpFuncList[gEquipRecover] = function(sysarg, args)
	local btRecoveryType = args[3]				-- 是否为vip随身回收, 1是, 0否
	local pos = args[5]							-- 位置0背包1寻宝仓库
	if pos == 1 and Actor.getIntProperty(sysarg, PROP_ACTOR_SUPER_VIP) == 0 then
		Actor.sendTipmsg(sysarg, Lang.ScriptTips.SuperVip003, ttFlyTip)
		return
	end
	if btRecoveryType == 2 then
		EquipGodCastRecover(sysarg, args)
	elseif btRecoveryType == 3 or btRecoveryType == 4 then
		EquipTheShenArmyRecover(sysarg, args, btRecoveryType)
	else
		EquipRecover(sysarg, args)
	end
end

--装备属性洗练
EquipOpFuncList[gEquipSmithFresh] = function(sysarg, args)
	local equipPtr 	= args[2]
	local Lock1 	= args[3]
	local Lock2 	= args[4]
	local Lock3 	= args[5]
	EquipSmithFresh( sysarg, equipPtr, Lock1, Lock2, Lock3 )
end

--装备属性洗练转移
EquipOpFuncList[gEquipSmithTrans] = function(sysarg, args)
	local equipPtrSrc = args[2]
	local equipPtrDes = args[3]
	EquipSmithTrans( sysarg, equipPtrSrc, equipPtrDes )
	--TestEquipSmithFresh( sysarg )
end

--装备升阶
EquipOpFuncList[gEquipGodCastUpgrade] = function(sysarg, args)
	local equipPtr = args[2]
	EquipGodCastUpgrade( sysarg, equipPtr )
	--TestEquipSmithFresh( sysarg )
end

--装备附魔
EquipOpFuncList[gEquipEnchant] = function(sysarg, args)
	local equipPtr 	= args[2]
	local Lock 		= args[3]
	EquipEnchant( sysarg, equipPtr, Lock )
end

--所有装备升阶
EquipOpFuncList[gEquipTSArmyUpgrade] = function(sysarg, args)
	local equipPtr 		= args[2]
	local equipIndex 	= args[3]
	local useInherit 	= args[4]
	local useAllEquip 	= args[5]
	EquipTSArmyUpgrade( sysarg, equipPtr, equipIndex, useInherit, useAllEquip )
end


function ShowEquipData(sysarg, itemPtr)
	local itemType 		= Item.getItemProperty( sysarg, itemPtr, Item.ipItemType, 0)
	local itemStar  	= Item.getItemProperty( sysarg, itemPtr, Item.ipItemStrong, 0)			--强化星级
	local lostStar		= Item.getItemProperty( sysarg, itemPtr, Item.ipItemLostStar, 0)		--损失星级
	local itemStarLimit	= Item.getItemProperty( sysarg, itemPtr, Item.ipItemStrongLimit, 0)		--该装备可强化限制(不大于itemStarMax)
	local itemStarMax	= GetEquipStarMaxByType( itemType )										--该类型装备可强化的最大星级

	local doStarMax		= 0																		--扣除损失星级是上限
	if itemStarLimit == 0 or itemStarLimit > itemStarMax then
		doStarMax = itemStarMax - lostStar
	else
		doStarMax = itemStarLimit - lostStar
	end
	print("装备强化数据: itemStar="..itemStar..", lostStar="..lostStar..", itemStarLimit="..itemStarLimit..", itemStarMax="..itemStarMax..
		", doStarMax="..doStarMax)

	local itemInject  		= Item.getItemProperty( sysarg, itemPtr, Item.ipItemInjectLevel, 0)			--注灵等级
	local itemInjectLimit	= Item.getItemProperty( sysarg, itemPtr, Item.ipItemInjectLimit, 0)			--该装备可注灵限制(取配置，不大于itemStarMax)
	local itemInjectMax		= GetEquipInjectMaxByType( itemType )										--该类型装备可强化的最大星级
	local doInjectMax		= 0
	if itemInjectLimit == 0 or itemInjectLimit > itemInjectMax then
		doInjectMax = itemInjectMax
	else
		doInjectMax 	= itemInjectMax
	end
	local injectPower = Actor.getUIntProperty(sysarg, PROP_ACTOR_INJECT_POWER)

	print("装备注灵数据, itemInject="..itemInject..", itemInjectLimit="..itemInjectLimit..", itemInjectMax="..itemInjectMax..
		", doInjectMax="..doInjectMax..", injectPower="..injectPower)

	local furnaceEquipPtr, furnaceLevel = GetEquipFurnaceByType( sysarg, itemType )
	if furnaceEquipPtr then		--已经有神炉装备
		local furnaceStar 	= Item.getItemProperty( sysarg, furnaceEquipPtr, Item.ipItemFurnaceStar, 0)
		print("神炉装备数据: itemType="..itemType..", furnaceStar="..furnaceStar..", furnaceLevel="..furnaceLevel)
	else
		print("神炉装备数据: 该装备不是神炉装备，itemType="..itemType)
	end

	local furnaceBloodRune 	= Actor.getUIntProperty(sysarg, PROP_ACTOR_FURANCE_BLOODRUNE)		--126 血符值
	local furnaceShield 	= Actor.getUIntProperty(sysarg, PROP_ACTOR_FURANCE_DIAMOND)			--127 神盾值
	local furnaceDiamond 	= Actor.getUIntProperty(sysarg, PROP_ACTOR_FURANCE_SHIELD)			--128 武魂值
	local furnaceSealBead 	= Actor.getUIntProperty(sysarg, PROP_ACTOR_FURANCE_SEALBEAD)		--129 灵珠值
	local acievePoint 		= Actor.getUIntProperty(sysarg, PROP_ACTOR_ACIEVEPOINT)				--68 成就值
	print("装备神炉数据, 血符值="..furnaceBloodRune..", 神盾值="..furnaceShield..", 武魂值="..furnaceDiamond..", 灵珠值="..furnaceSealBead..
		", 成就点="..acievePoint)

	CheckSetEquipFurnaceByIdx( sysarg, FurnaceEquipIdx_BloodRune, 10 )
	CheckSetEquipFurnaceByIdx( sysarg, FurnaceEquipIdx_Shield, 22 )
	CheckSetEquipFurnaceByIdx( sysarg, FurnaceEquipIdx_Diamond, 33 )
	CheckSetEquipFurnaceByIdx( sysarg, FurnaceEquipIdx_SealBead, 44 )
	CheckSetEquipFurnaceByIdx( sysarg, FurnaceEquipIdx_Decoration, 100 )
end


EventCallDispatcher.HandlerAddEquiment = function (sysarg, args)
	local equimentId = args[1]
	local equimentCount = args[2]
	local equipPtr = args[3]
	
	-- 处理玩家佩戴装备
	OnPlayerDressEquiment(sysarg, equipPtr, equimentId, equimentCount);
end

EventCallDispatcher.HandlerDelEquiment = function (sysarg, args)
	-- 处理玩家佩戴装备
	OnPlayerDelEquiment(sysarg);
end




EventCallDispatcher.registerEventCall(BaseTypes.ActorEventId.aeEquipOp, EventCallDispatcher.HandlerEquipOp)
EventCallDispatcher.registerEventCall(BaseTypes.ActorEventId.aeAddEquiment, EventCallDispatcher.HandlerAddEquiment)
EventCallDispatcher.registerEventCall(BaseTypes.ActorEventId.aeDelEquiment, EventCallDispatcher.HandlerDelEquiment)
